# names=["xwe","wewe","rfev","tvy"]
# names=[]

# items=['a','b','c']
# names=[1,2,3,4,"qws",items]
# print(names[5][0],type(names))


# #0-99 列表
# nums=range(1,100,1)
# print(nums)

nums=[1,2,3,4,5]
# list=[]
# for num in nums:
#     if(num%2 !=0):
#         list.append(num**2)
#
# print(list)

# #列表推导式
# list=[num**2 for num in nums if num%2!=0]
# list=[num**2 for num in nums for num2 in nums]
# print(list)

#增删查改
# #append 加在列表最后
# nums=[1,2,3,4]
# print(nums)
#
# nums.append(5)
# print(nums)
# print(nums.append(5))

#insert 在指定索引前，加一个新元素
# nums=[1,2,3,4]
# nums.insert(2,5)
#print(nums)

#extend  往列表中，扩展另外一个可迭代序列
# nums=[1,2,3,4]
# nums2=['a','b','c']
# print(nums.extend(nums2))
# print(nums)

# nums=[1,2,3]
# print(nums*3)

# n1=[1,2,3]
# n2="ab"
# print(n1.extend(n2))#扩展字符串 extend会分解字符串
# print(n1)

#def 删除一个指定元素（对象）
# nums=[1,2,3,4,5]
# del nums
# print(nums)

# num=66
# del num
# print(num)

#pop 移除并返回列表中指定索引对应元素

# nums=[1,2,3,4,5]
# result=nums.pop()#默认里面参数是-1 即最后一个
# print(result,nums)


#remove 移除列表中指定元素 若存在多个从左往右先出现先删除
# nums=[1,2,3,2,4,5]
# nums.remove(2)
# print(nums)

# nums=[1,2,2,2,3,4,2]
# # nums.remove(2)
# print(nums)
# for num in nums:
#     print(num)
#     if(num==2):
#         nums.remove(2)
# print(nums)

# nums[0]=6
# print(nums)

#查
# nums=range(10)
# nums=[3,4,5,6,7,5,8,9]
# print(nums[-1])
#
#
# idx=nums.index(5,3)#有多个数字，从左到右选优先出现的
# print(idx)
#
# c=nums.count(5)
# print(c)

# nums=[3,4,5,6,7,5,8,9]
# pic=nums[::-1]
# print(pic)


# values=['a','a','b','c','d']
# currentIndex = 0
# for v in values:
#     print(v)
#     print(values.index(v, currentIndex))
#     currentIndex+=1


# values=['a','b','c','d','e']
# indexs=range(len(values))
# for index in indexs :
#     print(index, values[index])



# values=['a','b','c','d','e']
# # print(enumerate(values))
# #创建一个枚举对象
# print(list(enumerate(values)))
#
# #遍历整个的枚举对象（枚举对象，可以直接被遍历）
# for idx,val in enumerate(values,1):
#     # print(tup)#元祖
#     # print(tup[0],tup[1])
#     # idx,val=tup
#     print(idx,val)

#迭代器
nums=[1,2,3]

# for num in nums:
#     print(num)

# import collections
from collections.abc import Iterable
# result=isinstance(nums,collections.Iterable)#判断能不能迭代
# print(result)

# result2=isinstance(nums,collections.Iterable)#判断是不是迭代器

# next(nums)

# i=iter(nums)
# print(i)
# result=isinstance(i,Iterable)#判断能不能迭代
# print(result)

#斐波那契
#写一个统一遍历代码
# list=[1,2,3,4,5]
# l=iter(list)

#next()
# print(next(l))
# print(next(l))

# for v in l:
#     print(v)

#判定
#  元素 in 列表
#  元素  not in 列表
# s="abc"
# print("a" in s)
# print("c" not in s)

# values=[1,2,3,4,5]
# print(5 in values)
# print(5 not in values)

# result=[2,3,4]<[2,3,3]
# print(result)

#排序
# s=[1,2,5,3,7,8,9]
# result=sorted(s,reverse=True)#不改变原列表
# # result=sorted(s)
# print(result,s)

# s=[("s1",18),("s2",17),("s3",16),("s4",15)]
#
# def getKey(x):
#     return x[1]
#
# result=sorted(s,key=getKey,reverse=True)
# print(result)

# l=[1,3,2,6,4,5]
# l=[("s1",18),("s2",20),("s3",16),("s4",15)]
# def getKey(x):
#     return x[1]
# res=l.sort(key=getKey,reverse=True)#改变原本列表
# print(res,l)

#乱序
# import random
# l=[1,2,3,4,5]
# res=random.shuffle(l)#改变列表本身
# print(res,l)

# res=l.reverse()#改变列表本身
# print(res,l)

# res=l[::-1]#不改变列表本身
# print(res,l)